package com.wydpp.utils;

import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @author jee
 * @version 1.0
 */
public class ReadSourcesUtil {

    private final static Logger logger = LoggerFactory.getLogger(ReadSourcesUtil.class);

    public static File readFile(String path) {
        try {
            if (SystemUtils.IS_OS_WINDOWS) {
                logger.info("当前系统windows ! Read Classpath:{} !", path);
                return ResourceUtils.getFile("classpath:" + path);
            } else {
                logger.info("当前系统非windows ! Read RelativePath:{} !!!", path);
                return ResourceUtils.getFile(path);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
